<template>
	<view class="bgColor-white">
		<cu-custom :key="'header'+headerKey" bgColor="bg-gradual-blue-light" :isBack="true" backText="返回" title="签到记录"></cu-custom>
		<uni-calendar 
		    :insert="true"
		    :lunar="false" 
		    :start-date="'2020-08-01'"
			:end-date="endDate"
		    @change="change"
			@monthSwitch="monthSwitch"
			:selected="selected"
		/>
		<view class="bg-white">
			<view class="text-center text-xl">
			<text>签到记录明细</text>
			</view>
			<view style="padding: 20rpx;" v-for="(item,index) in signInList" :key="index">
				<view style="display: flex;justify-content: space-between;align-items: center;">
					<view><text style="padding-right: 20rpx;">{{item.time}}</text>签到</view>
					<view :style="{'color':item.success=='1'?'#0081ff':'#f43f3b'}">{{item.msg}}</view>
				</view>
				<view class="text-left">
					地点：<text>{{item.locationAddress}}</text>
				</view>
				<view v-if="item.remarks"class="text-left ">
					备注：<text class="text-gray">{{item.remarks}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import miment from 'miment'
	import api from '@/api/society/home/signIn.js'
	export default {
		onShow() {
			this.headerKey += 1;
		},
		data() {
			return {
				headerKey:0,
				endDate:miment().format('YYYY-MM-DD'),
				selected:[],
				signInList:[]
			}
		},
		onReady() {
			const ym=miment().format('YYYYMM')
			this.getSelected(ym)
			const signInDate=miment().format('YYYYMMDD')
			this.getDateList(signInDate)
		},
		methods: {
			change(e) {
			    console.log(e);
				const signInDate=e.fulldate
				this.getDateList(signInDate)
			},
			monthSwitch(e){
				console.log(e);
				let ym = e.year
				if(e.month.toString().length==1){
					ym = e.year.toString()+'0'+e.month.toString()
				}else{
					ym = e.year.toString()+e.month.toString()
				}
				this.getSelected(ym)
			},
			getSelected(ym){
				const data = {}
				data.ym=ym
				data.signInType='common'
				this.$http.post(api.getSelected, data).then(res => {
					//console.log(res.result)
					this.selected = res.result
				}).catch(error => {	
				})
			},
			getDateList(signInDate){
				const data = {}
				data.signInDate=signInDate
				data.signInType='common'
				this.$http.post(api.getByDate, data).then(res => {
					const signInList = []
					for(var num in res.result){
						const signIn = res.result[num]
						signIn.time = miment(signIn.signInTime).format('hh:mm:ss')
						signInList.push(signIn)
					}
					this.signInList = signInList
				}).catch(error => {	
				})
			}
		}
	}
</script>

<style>

</style>
